package String;

public class _551_StudentAttendanceRecordI {
    public boolean checkRecord(String s) {
        int length = s.length();
        int absentCount = 0;
        for(int i=0;i<length-2;i++) {
            if (s.charAt(i) == 'A') {
                absentCount++;
            } else if (s.charAt(i) == 'L') {
                if (s.charAt(i + 1) == 'L' && s.charAt(i + 2) == 'L') {
                    return false;
                }
            }
        }
        for(int i=(length-2>-1?length-2:0);i<length;i++) {
            if (s.charAt(i) == 'A') {
                absentCount++;
            }
        }
        if (absentCount > 1) {
            return false;
        }
        return true;
    }

    //reference fast solution
    public boolean checkRecord1(String s) {
        if (s.length() == 0) {
            return true;
        }
        return !(s.indexOf('A')!=s.lastIndexOf('A')) && !s.contains("LLL");
    }

    //upper solution another form,but faster
    public boolean checkRecord1_1(String s) {
        if(s.length() == 0) return true;
        if(s.indexOf("A") != s.lastIndexOf("A") || s.contains("LLL")) return false;
        return true;

    }
}
